from financial_market import *
df_concat, df_sector_dict, symbols = load_dataframe()
df_concat
df, df_sector, df_both, not_done_for = get_closing_prices(symbols, df_sector_dict)
# these have become nan because symbols has values that aren't collected
print(df.isnull().values.any(), not_done_for)
print(df.columns[df.isna().any()].tolist())
df.to_excel("output/excel/sp500_stock_names.xlsx")
df_sector.to_excel("output/excel/sp500_sector_names.xlsx")
df_both.to_excel("output/excel/sp500_both.xlsx")
df.to_csv("output/csv/sp500_stock_names.csv")
df_sector.to_csv("output/csv/sp500_sector_names.csv")
df_both.to_csv("output/csv/sp500_both.csv")
# here you can change the stock to be plotted to any other
# ticker value that you want to be plotted
stock_to_be_plotted = "AAPL"
plot_candlesticks(stock_to_be_plotted)
plt.plot(df["date"], df["AAPL"])
Here you can clearly see the stock name as well as the sector the stock belongs to (format: stock_sector)
df_both = pd.read_csv("output/csv/sp500_both.csv", index_col=None)
df_both = df_both.iloc[:, 1:]
df_both["date"] = df_both['date'].apply(pd.to_datetime)
plot_all_charts(df_both)
# df = pd.read_excel("output/excel/sp500_sector_names.xlsx", sheet_name="Sheet1", index_col=None)
df = pd.read_csv("output/csv/sp500_sector_names.csv", index_col=None)
df = df.iloc[:, 2:]
# this is without calculating the log returns.
plot_corr_mat(df)
# calculating log returns and then plotting
for i in df.columns:
df[i] = np.log(df[i]/df[i].shift(1))
df = df.iloc[1:, :]
plot_corr_mat(df)
dict_col = ticker_val_locations(df)
fig, axes = plt.subplots(len(df) // (200 * 3), 3, figsize=(20, 5 * (len(df) // (200 * 3))))
count = 0
for i in range(0, len(df) - 200, 200):
try:
p = sns.heatmap(df.iloc[i:i+400,:].corr(), ax=axes[count//3, count%3])
p.set_xticks(ticks=list(dict_col.values()), labels=list(dict_col.keys()))
p.set_yticks(ticks=list(dict_col.values()), labels=list(dict_col.keys()))
count += 1
except:
pass